﻿<%@page contentType="text/html; charset=UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@page import="java.net.URLDecoder"%>
<%@ page import="java.util.*"%>
<%@ page import="com.cb.core.util.AppUtil"%>
<%@ page import="webservices.alipaydirect.util.*"%>
<%@ page import="webservices.alipaydirect.services.*"%>
<%@ page import="webservices.alipaydirect.config.*"%>
<%@ page import="com.cb.domain.service.order.BOrderManager"%>
<html>
  <head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>支付结果页面</title>
		<link href="${ctxPath}/resource/front/css/international_ticket.css"rel="stylesheet" type="text/css" />
  </head>
  <body>
  
   <%
	//获取支付宝GET过来反馈信息
	Map<String,String> params = new HashMap<String,String>();
	   Map requestParams = request.getParameterMap();
		for(Iterator iter=requestParams.keySet().iterator();iter.hasNext();){
			String name = (String) iter.next();
			String[] values = (String[]) requestParams.get(name);
			String valueStr = "";
			for (int i = 0; i < values.length; i++) {
				valueStr = (i == values.length - 1) ? valueStr + values[i]
						: valueStr + values[i] + ",";
			}
			//乱码解决，这段代码在出现乱码时使用。如果mysign和sign不相等也可以使用这段代码转化
			valueStr= new String(valueStr.getBytes("iso8859-1"), "UTF-8");
			params.put(name, valueStr);
		}
		
		//获取支付宝的通知返回参数，可参考技术文档中页面跳转同步通知参数列表(以下仅供参考)//

		String trade_no = request.getParameter("trade_no");				//支付宝交易号
		String order_no = request.getParameter("out_trade_no");	        //获取订单号
		String total_fee = request.getParameter("total_fee");	        //获取总金额
		//String subject = new String(request.getParameter("subject").getBytes("ISO-8859-1"),"utf-8");//商品名称、订单名称
		String subject = request.getParameter("subject");//商品名称、订单名称
		String body = "";
		if(request.getParameter("body") != null){
			//body = new String(request.getParameter("body").getBytes("ISO-8859-1"), "utf-8");//商品描述、订单备注、描述
			body =request.getParameter("body");//商品描述、订单备注、描述
		}
		String buyer_email = request.getParameter("buyer_email");		//买家支付宝账号
		String trade_status = request.getParameter("trade_status");		//交易状态
		//获取支付宝的通知返回参数，可参考技术文档中页面跳转同步通知参数列表(以上仅供参考)//
		
		//计算得出通知验证结果
		boolean verify_result = AlipayNotify.verify(params);
		boolean flag=false;
		if(verify_result){//验证成功
			//请在这里加上商户的业务逻辑程序代码

			if(trade_status.equals("TRADE_FINISHED") || trade_status.equals("TRADE_SUCCESS")){
				//判断该笔订单是否在商户网站中已经做过处理（可参考“集成教程”中“3.4返回数据处理”）
					//如果没有做过处理，根据订单号（out_trade_no）在商户网站的订单系统中查到该笔订单的详细，并执行商户的业务程序
					//如果有做过处理，不执行商户的业务程序
				BOrderManager bOrderManager=(BOrderManager)AppUtil.getById("bOrderManager");
				flag= bOrderManager.saveByOrderNo(order_no,total_fee);
			}
		}
		request.setAttribute("flag",flag);
	%>
	
  <div id="col" style="width:1000px;margin:0px auto;">
   <div id="affirmance">
	<ul class="ticket_list_title">
	  <table width="100%"  border="0" cellspacing="0" cellpadding="0">
  		<tr>
    	  <td><img src="${ctxPath}/resource/front/image/public/news_dot.gif" width="5" height="12" align="absmiddle"/>&nbsp;&nbsp;支付信息情况</td>
    	  <td align="right">&nbsp;</td>
  		</tr>
	  </table>
    </ul>
	   <ul class="orders">
	  <c:if test="${flag==true}">
	
				<ul>
				<li class="pay_success"><img src="${ctxPath}/resource/front/image/pay/001_06.gif" align="absmiddle"/> 您的订单支付成功！ </li>
				<li class="pay_next">如需继续预订，请按此处 <a href="${ctxPath}/front/index.do"><font color="#0033FF"><u>返回</u></font></a></li>
				<li class="pay_next">如有疑问，请拨打客服热线：4007-168-138</li>
				</ul>
				<ul><img class="img1" src="${ctxPath}/resource/front/image/pay/errimg.png"/>
				</ul>
		</c:if>

	  <c:if test="${flag==false}">
			<ul>
			<li class="pay_no"><img src="${ctxPath}/resource/front/image/international_ticket/001_30.gif" align="absmiddle"/> 您的订单支付失败！ </li>
			<li class="pay_next">请按此处 <a href="${ctxPath}/front/order/orderSearch.do?cmd=doAffirmance&tradeNo=${param['out_trade_no']}"><font color="#0033FF"><u>重新支付</u></font></a>，系统将会为您跳转回页面</li>
			<li class="pay_next">如有疑问，请拨打客服热线：4007-168-138</li>
			</ul>
			<ul><img class="img" src="${ctxPath}/resource/front/image/pay/err.png"/></ul>
			<ul><img class="img1" src="${ctxPath}/resource/front/image/pay/errimg.png"/>
			</ul>
	  </c:if>
  	</ul>
</div>
</div>
  </body>
</html>
